//
//  MBProgressHUD+DV.m
//  DoctorVideo
//
//  Created by 锦食送 on 2019/8/9.
//  Copyright © 2019 lzx. All rights reserved.
//

#import "MBProgressHUD+DV.h"

@implementation MBProgressHUD (DV)
/**
 *  快速显示一条提示信息
 *
 *  @param message 要显示的文字
 */
+ (void)dv_showAutoMessage:(NSString *)message {
    UIView *window = [UIApplication sharedApplication].delegate.window;
    if (!NULLString(message)) {
        [MBProgressHUD dv_showToast:message hideAfter:1.5 withWindow:window];
    }
}

+ (void)dv_showAutoMessage:(NSString *)message withWindow:(UIView *)window {
    [MBProgressHUD dv_showToast:message hideAfter:1.5 withWindow:window];
}

+ (void)dv_showToast:(NSString *)msg hideAfter:(NSTimeInterval)interval withWindow:(UIView *)window {
    MBProgressHUD *hud = [[MBProgressHUD alloc] initWithView:window];
    hud.removeFromSuperViewOnHide = YES;
    hud.mode = MBProgressHUDModeText;
    hud.detailsLabel.text = msg;
    hud.detailsLabel.textColor = [UIColor whiteColor];
    hud.bezelView.backgroundColor = [UIColor blackColor];
    [window addSubview:hud];
    [hud showAnimated:YES];
    [hud hideAnimated:YES afterDelay:interval];
}
+(void)showLoadingView:(UIView *)view{
    
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
    hud.mode = MBProgressHUDModeIndeterminate;
    hud.label.text = @"请稍等...";
}


+(void)showLoadingView:(UIView*)view andText:(NSString*)tipText{
    
    
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
    hud.mode = MBProgressHUDModeIndeterminate;
    hud.label.text = tipText;
}

+(void)showLoadingView:(UIView*)view andText:(NSString*)tipText alpha:(CGFloat )alpha{
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
    hud.mode = MBProgressHUDModeIndeterminate;
//    hud.backgroundColor = DV_RGBA_COLOR(0, 0, 0, alpha);
    hud.label.text = tipText;
}
+(void)showLoadingView:(UIView *)view andText:(NSString *)tipText andOffsetY:(CGFloat)offsety{
    
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
    //是否有遮罩
    hud.backgroundColor=[UIColor clearColor];
   
    [hud setOffset:CGPointMake(0, offsety)];
    hud.label.text=tipText;
}

+(void)hideLoadingView:(UIView *)view{
    
    [MBProgressHUD hideHUDForView:view animated:YES];
}

+(void)showDoneWith:(UIView*)view isSucess:(Boolean)isSucess completion:(void(^)(void))completion{
    
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
    
    hud.mode = MBProgressHUDModeCustomView;
    UIImage *image;
    if(isSucess){
        image = [[UIImage imageNamed:@"Checkmark"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
        hud.label.text = NSLocalizedString(@"保存成功", @"");
    }else{
        image = [[UIImage imageNamed:@"Checkmark_wrong"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
        hud.label.text = NSLocalizedString(@"保存失败", @"");
    }
    
    hud.customView = [[UIImageView alloc] initWithImage:image];
    
    hud.square = YES;
    
    [hud hideAnimated:YES afterDelay:3.f];
    dispatch_time_t delayTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(4.f * NSEC_PER_SEC));
    dispatch_after(delayTime, dispatch_get_main_queue(), ^{
        if(completion){
            completion();
        }
        
    });
    
}

+(void)showDoneWith:(UIView*)view tilte:(NSString*) title isSucess:(Boolean)isSucess completion:(void(^)(void))completion{
    
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
    
    hud.mode = MBProgressHUDModeCustomView;
    UIImage *image;
    if(isSucess){
        image = [[UIImage imageNamed:@"Checkmark"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
        hud.label.text = NSLocalizedString(title, @"");
    }else{
        image = [[UIImage imageNamed:@"Checkmark_wrong"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
        hud.label.text = NSLocalizedString(title, @"");
    }
    
    hud.customView = [[UIImageView alloc] initWithImage:image];
    
    hud.square = YES;
    
    [hud hideAnimated:YES afterDelay:3.f];
    dispatch_time_t delayTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(4.f * NSEC_PER_SEC));
    dispatch_after(delayTime, dispatch_get_main_queue(), ^{
        if(completion){
            completion();
        }
        
    });
    
}

@end
